using System;
using System.Collections.Generic;
using System.Text;
using MULENetworking;

namespace MULEServer
{
    public class UsageSpoilage
    {
        public UsageSpoilage()
        {

        }

        public int foodUsage(IPlayer player)
        {
            player.food -= player.plotsOwned.Count + 1;
            return (player.plotsOwned.Count + 1);
        }
        public int energyUsage(IPlayer player)
        {
            int numMules = 0;
            IMapSquare tempSquare;
            for (int i = 0; i < player.plotsOwned.Count; i++)
            {
                tempSquare = (IMapSquare)player.plotsOwned[i];
                if (!tempSquare.Mule.Equals("empty"))
                {
                    numMules++;
                }
            }
            numMules++;
            player.energy -= numMules;
            return numMules;
        }

        //Spoilage methods are to be called only after
        //usage has been calculated.
        public int smithoreSpoilage(IPlayer player)
        {
            int toReturn = 0;
            if (player.smithore > 50)
            {
                toReturn = player.smithore - 50;
                player.smithore = 50;
            }
            return toReturn;
        }
        public int foodSpoilage(IPlayer player)
        {
            int spoilage = 0;
            if (player.food > 0)
            {
                spoilage = player.food / 2;
                player.food -= spoilage;
            }
            return spoilage;
        }
        public int energySpoilage(IPlayer player)
        {
            int spoilage = 0;
            if (player.energy > 0)
            {
                spoilage = player.energy / 4;
                player.energy -= spoilage;
            }
            return spoilage;
        }
    }
}
